home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Auge 4000
/
Auge 4000 #21 (1988-05-25)(Amiga User Gruppe Einzugsgebiet 4000).zip
/
Auge 4000 #21 (1988-05-25)(Amiga User Gruppe Einzugsgebiet 4000).adf
/
Mastermind
/
Mastermind
(
.txt
)
< prev
next >
Wrap
AmigaBASIC Source Code
|
1988-01-20
|
10KB
|
462 lines
' Mastermind V1.0 860804
'
' The good ol' game of Mastermind...
' It's the machine playing the scorekeeper and the ever-lasting oponent
' who does all of the puzzle choosing. Choose between Mastermind and
' SUPER Mastermind (heh heh heh)
'
' Programmed By Ken Robertson of Montreal, Quebec
' August 1st, 1986
'
'
' This program is FREEWARE and may be distributed without cost to anyone.
' However, if you like the game and would like to see more coming, feel
' free to send me a donation (I gotta eat, too) at
'
' 4130 Decarie, #11
' Montreal, Quebec,
' Canada
' H3A 2K1
'
' I didn't put these comments in to print at the beginning as I feel
' that they're a little tacky to see, everytime the program comes up.
'
' Any programs that begin with 'KenR Software Presents' was most probably
' written by me. Expect good stuff.
'
DIM guess(5),rack(20,5),answer(5),unguess(5)
' paint function key boxes for colours, cancel, and erase.
RANDOMIZE TIMER
SCREEN CLOSE 2
SCREEN 2,640,200,4,2
WINDOW 2,"Mastermind",,15,2
PALETTE 0,0,0,0:PALETTE 1,0.7,0.7,0.7:PALETTE 8,0,0.5,0:PALETTE 10,1,1,0.13
GOSUB drawcredits
thesame=0
FOR i=0 TO 9
LINE (i*60-30*(i>4),174)-(i*60-30*(i>4)+40,186),i+3,bf
NEXT i
LINE (8*60+30,174)-(8*60+70,186),0,bf
LOCATE 23,73
PRINT " Go ";
topscore=99
LOCATE 1,1:PRINT "For instructions, press the 'Help' key now."
firstime=1
thesame=0
startgame:
' Generate permutation . . .
answer(0)=0
FOR i=1 TO 5
test1:
g=INT(RND(1)*8)+1
IF thesame=0 THEN
testf=0
FOR j=0 TO i-1
IF g=answer(j) THEN testf=1
NEXT j
IF testf=1 THEN test1
END IF
answer(i)=g
NEXT i
' No two balls alike...
guessnbr = 1
' draw rack
FOR i=14 TO 550 STEP 29
LINE (i,14)-(i+29,77),1,b
NEXT i
notdone = -1
WHILE notdone
guessing = -1
lastx=guessnbr*29
lasty=22
inpnbr = 1
WHILE guessing
CIRCLE (lastx,lasty),12,1
nochar=-1
WHILE nochar
a$=INKEY$
IF LEN(a$)<>0 THEN
a=ASC(a$)
IF a>128 AND a<140 THEN nochar=0
IF a=28 OR a=29 THEN nochar = 0
IF a=139 AND firstime=1 THEN GOSUB help
END IF
WEND
IF a<>139 AND a<>137 THEN firstime=0
IF a=139 AND firstime=0 THEN GOSUB hint
IF a=137 AND firstime THEN
thesame=1
COLOR 3
LOCATE 1,1
firstime=0
PRINT "A more difficult game has just been chosen. Pegs may now be the same color.";
GOTO startgame
END IF
SOUND 220,0.31,127,0
SOUND 245,0.31,127,1
' clear the first line of any message
LINE (0,0)-(639,9),0,bf
'
' A function key was pressed or an arrow key - is it a guess?
'
IF a<137 AND a>128 THEN
' Yep - add it to the list
rack (guessnbr,inpnbr)=a-128
'draw the circle
CIRCLE (lastx,lasty),11,a-126
PAINT (lastx,lasty),a-126
inpnbr=inpnbr + 1
END IF
CIRCLE (lastx,lasty),12,0
IF a=28 THEN inpnbr=inpnbr-1
IF inpnbr=0 THEN inpnbr=1
IF a=29 THEN inpnbr=inpnbr+1
IF inpnbr = 6 THEN inpnbr = 1
lastx=guessnbr*29:lasty=inpnbr*12+10
CIRCLE (lastx,lasty),12,1
IF a=138 THEN
n=1
FOR i=1 TO 5
n=n*rack(guessnbr,i)
NEXT i
IF n<>0 THEN
guessing=0
ELSE
LOCATE 1,1
COLOR 3
PRINT "You must finish guessing before you 'Go'.";
SOUND 200,3,127,0
SOUND 210,3,127,1
SOUND 150,3,127,0
SOUND 160,3,127,1
END IF
END IF
WEND
'An input has been entered! Check it against the answer
CIRCLE (lastx,lasty),12,0
FOR i=1 TO 5:guess(i)=answer(i):unguess(i)=rack(guessnbr,i):NEXT i
white=0:black=0
FOR i=1 TO 5
FOR j=1 TO 5
IF unguess(i)=guess(j) AND i=j THEN black=black+1:guess(j)=0:unguess(i)=99
NEXT j
NEXT i
FOR i=1 TO 5
FOR j=1 TO 5
IF unguess(i)=guess(j) THEN white=white+1:guess(j)=0:unguess(i)=99
NEXT j
NEXT i
' ok - blacks and whites are summed up
IF black>0 THEN
FOR i=1 TO black
CIRCLE (guessnbr*29,75+6*i),5,1
SOUND 800,0.1,127,0
SOUND 810,0.1,127,0
NEXT i
END IF
IF white > 0 THEN
FOR i=1 TO white
CIRCLE (guessnbr*29,75+6*black+6*i),5,7
PAINT (guessnbr*29,75+6*black+6*i),7
SOUND 500,0.1,127,0
SOUND 510,0.1,127,1
NEXT i
END IF
LINE (14+(guessnbr-1)*29,77)-(guessnbr*29+14,110),1,b
guessnbr = guessnbr + 1
IF black=5 THEN notdone = 0
IF guessnbr=20 THEN notdone=0
WEND
LOCATE 1,1
IF guessnbr=20 AND black=5 THEN
FOR i=500 TO 100 STEP -10
SOUND i,0.1,100,0
SOUND i,0.1,100,1
NEXT i
PRINT "Wow. You just got lucky, I guess.";
END IF
IF guessnbr=20 AND black<5 THEN
SOUND 200,10,100,0
SOUND 300,10,100,1
PRINT "Sorry, you've run out of turns. The puzzle was:";
lastx=guessnbr*29
FOR i=1 TO 5
lasty=i*12+10
CIRCLE (lastx,lasty),11,answer(i)+2
PAINT (lastx,lasty),answer(i)+2
NEXT i
END IF
IF guessnbr<20 AND guessnbr < topscore THEN
SOUND 200,5,100,0
SOUND 500,5,100,0
SOUND 200,5,100,1
SOUND 500,5,100,1
PRINT "You've got it! And beat the topscore!";
END IF
IF guessnbr<20 AND guessnbr > topscore THEN
SOUND 200,5,100,0
SOUND 500,5,100,0
SOUND 300,5,100,0
SOUND 200,5,100,1
SOUND 500,5,100,1
SOUND 300,5,100,1
PRINT "Well, you've got it, but you've done better.";
END IF
IF guessnbr < topscore THEN topscore=guessnbr-1
PRINT " Press any key to continue.";
GOSUB keywait
LOCATE 20,1:COLOR 4:PRINT "Top Score: ";topscore;
total=total+guessnbr
games=games+1
IF games>1 THEN COLOR 3:PRINT " Average: ";total/games
LINE (0,0)-(619,110),0,bf
GOTO startgame
drawcredits:
' Draw Opening Credits
'set border to black as well
LOCATE 12,29
PALETTE 1,0,0,0:PALETTE 3,1,1,1:COLOR 3
PRINT "KenR Software Presents";
FOR i=1 TO 1500:x=0.1:NEXT i
FOR i=1 TO 0 STEP -0.02
PALETTE 3,i,i,i
SCROLL (0,0)-(639,220),0,-1
NEXT i
CLS
FOR i=3 TO 5
PALETTE i,0.01,0.01,0.01
NEXT i
COLOR 3
cl=3:cll=1
notend = -1
WHILE notend
READ x,y
IF x=0 AND y=0 THEN notend=0
newletter=1*notend
WHILE newletter
READ x1,y1
IF x1=0 AND y1=0 THEN
AREAFILL
newletter=0
ELSE
AREA (x*15+40,y*10+10)
x=x1:y=y1
END IF
WEND
cl=cl+1:IF cl=6 THEN cl=3
COLOR cl
WEND
y=0
FOR z=0 TO 0.8 STEP 0.04
SOUND 130,1,z*100,0
SOUND 131,1,z*100,1
PALETTE 3,z,y,0
PALETTE 4,0,z,y
PALETTE 5,y,0,z
y=y+0.02
SOUND 130,1,z*100,0
SOUND 131,1,z*100,1
PALETTE 3,z,y,0
PALETTE 4,0,z,y
PALETTE 5,y,0,z
NEXT z
FOR j=1 TO 50
SOUND 130,1,80,0
SOUND 131,1,80,1
SOUND 130,0.1,0,0
SOUND 131,0.1,0,0
IF RND(1)>0.9 THEN
n1=RND(1):n2=RND(1):n3=RND(1)
PALETTE 0,n1,n2,n3
PALETTE 1,n1,n2,n3
SOUND 3900,0.3,127,2
SOUND 5000,0.3,127,3
PALETTE 0,0,0,0
PALETTE 1,0,0,0
END IF
NEXT j
FOR z=0.8 TO 0 STEP -0.02
SOUND 130,1,z*100,0
SOUND 131,1,z*100,1
SOUND 133,1,z*100,2
SOUND 134,1,z*100,3
PALETTE 3,z,0,0
PALETTE 4,0,z,0
PALETTE 5,0,0,z
NEXT z
CLS
PALETTE 3,0.8,0.6,0.53
PALETTE 4,0.3,0.4,1
PALETTE 5,1,0.13,0.93
PALETTE 6,0.2,0.93,0.87
PALETTE 1,0.7,0.7,0.7
SOUND 50,25,127,0
SOUND 51,25,127,1
SOUND 100,10,127,0
SOUND 101,10,127,1
FOR i=127 TO 0 STEP -20
SOUND 100,2,i,0
SOUND 101,2,i,1
NEXT i
RETURN
DATA 30,11,30,5,33,7,32,10,30,11,0,0
DATA 29,11,29,5,30,8,31,5,30,11,29.5,7,29,11,0,0
DATA 28,11,27,8,28,5,29,8,28,11,0,0
DATA 20,11,23,5,24,7,25,5,28,11,20,11,0,0
DATA 18.5,11,18.5,5,22,6,20,8,22,11,19.5,8.5,18.5,11,0,0
DATA 16,11,16,5,19,6,17,7,19,8,17,9,19,10,16,11,0,0
DATA 14.5,11,14.5,6.5,13,5.5,15,5,17,5.5,15.5,6,15.5,11,14.5,11,0,0
DATA 13,11,10,8,12,9,11,6,12,5,14,6,12,7,14,10,13,11,0,0
DATA 8,11,10,5,12,11,8,11,0,0
DATA 0,11,3,0,4,4,5,0,10,11,0,11,0,0
DATA 0,0
help:
LOCATE 12,1
COLOR 5
PRINT "This is the game of Mastermind. Originally by Parker Brothers, the";
LOCATE 13,1
PRINT "object of the game is to guess the 5 colors of the pegs in the";
LOCATE 14,1
PRINT "puzzle." ;
LOCATE 15,1
PRINT " These colors may be of any of the 8 boxes below, each of which";
LOCATE 16,1
PRINT "correspond to a function key on your keyboard. (Novel idea, eh?)";
LOCATE 17,1
COLOR 1
PRINT "Press any key to go on.";
GOSUB keywait
' clear area
LINE (0,80)-(639,170),0,bf
COLOR 6
LOCATE 12,1
PRINT "As you make each guess, the round cursor will automatically advance to";
LOCATE 13,1
PRINT "the next space. You can use the up and down cursor keys to move the cursor";
LOCATE 14,1
PRINT "as well.";
COLOR 1
LOCATE 15,1
PRINT "Press any key to go on.";
GOSUB keywait
' clear area
LINE (0,80)-(639,170),0,bf
LOCATE 12,1:COLOR 7
PRINT " After you are satisfied that your guess is what you want, press F10";
LOCATE 13,1
PRINT "(The box that has 'Go' in it) to register your guess.";
LOCATE 14,1
PRINT " The Amiga will tell you if 1) A 'peg' is in the right spot";
LOCATE 15,1
PRINT " or 2) The color is correct, but the spot";
LOCATE 16,1
PRINT " is not.";
LOCATE 17,1
PRINT "These are signified by a black circle and a white circle respectively.";
COLOR 1
LOCATE 18,1
PRINT "Press any key to go on.";
GOSUB keywait
' clear area
LINE (0,80)-(639,170),0,bf
LOCATE 12,1:COLOR 8
PRINT " - All spots must be full in order to make a guess." ;
LOCATE 13,1
PRINT " - The pegs will all be different colors, unless you want a harder";
LOCATE 14,1
PRINT " game - in which case, press F9 when you exit help (or when you start";
LOCATE 15,1
PRINT "up the game next time.)";
LOCATE 16,1
COLOR 9
PRINT "By the way, you can only access help UNTIL you make a guess. After that,";
LOCATE 17,1
PRINT "I'd think you're asking for a hint. I MAY give you one, but it'll cost.";
COLOR 1
LOCATE 18,1
PRINT "Press any key to go back.";
GOSUB keywait
' clear area
LINE (0,80)-(639,170),0,bf
LOCATE 12,1:COLOR 9
RETURN
keywait:
' first clear the buffer
nochar=-1
WHILE nochar
a$=INKEY$
IF LEN(a$)=0 THEN nochar=0
WEND
' now wait for the next key
nochar=-1
WHILE nochar
a$=INKEY$
IF LEN(a$)<>0 THEN nochar=0
WEND
RETURN
hint:
LOCATE 1,1
COLOR 8
PRINT "Hints are not available in this version.";
RETURN